<?php
/**
 *  @author: Pham Van Diep
 *  @date:   26/2/2014
 *  @status: 6->save
 *           1->active
 *           2->delete ( not delete out database)
 * 
 **/

if( !isset($AppUI) || 
	!isset($_SESSION['personal'])||
	!isset($_POST['personalid'])
) {
	redirect(HOST_BACKEND);
}
$intAction 		= $this->input->post('paction', -1);
$intPersonalId  = $this->input->post('personalid'); 

if($intAction) {
	switch ($intAction) {        		
         case 6:          // save national
		 	// personal not allow add
		 	if( ($_SESSION['personal'] &1<<1) == 0 ) break;
			if(!$intPersonalId) break;
             $arrNationalId 	= $this->input->post('nationalid', null);
			 if(!empty($arrNationalId)) {
				$this->load->model('national_model','national');
				 foreach($arrNationalId as $code ) {					 			 
					$ret = $this->national->add($AppUI->id,$intPersonalId,trim(strtolower($code)));							
					if($ret != 0) CI_Function::setError($arrError['problem_save_db_error']);
					else  CI_Function::setMsg($arrMessage['success']);
				 }
				
			 }else{
				 CI_Function::setError($arrError['nodata_act']);
			}
            break;         
		default:
            break;
		
	}
} else {
	CI_Function::setError($arrError['nodata_act']);
}

redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);

